import type { IJsonSchema } from "@/types/common";
import type { IPreSettingComsUnions } from "@/types/store";
import { defaultJsonSchemaMap } from "@/configs/defaultStatus/defaultJsonSchemaMap";

/*
  * 预设组件说明：
  ? 所有的【预设组件】都是【基于题目组件】 Json Schema 基础之上设置了一个特定的初始值
  - 例如：【姓名】预设组件 是基于【文本输入】组件 基础之上设置了一个特定的初始值
*/

// - 记录 预设组件 的名称
export const preSettingComsName: IPreSettingComsUnions[] = [
  // * 预设组件的默认状态-个人信息
  "personal-info-name",
  "personal-info-id",
  "personal-info-birth",
  "personal-info-gender",
  "personal-info-age",
  "personal-info-education",
  "personal-info-collage",
  "personal-info-major",
  "personal-info-industry",
  "personal-info-career",
  "personal-info-company",
  "personal-info-position",
  // * 预设组件的默认状态-联系方式
  "contact-way-phone",
  "contact-way-wechat",
  "contact-way-qq",
  "contact-way-email",
  "contact-way-address",
];

/**
 * 获取 预设组件 的初始状态
 * @returns 返回 预设组件 的初始状态 的映射对象
 */
export const getPreSettingComsInitialStatus = () => {
  // - 记录 预设组件初始状态 的映射对象
  const preSettingComsMap: Partial<Record<IPreSettingComsUnions, IJsonSchema>> =
    {};
  preSettingComsName.forEach((name) => {
    // + 获取当前预设组件对应题目组件的Json schema
    const defaultComJsonSchema = defaultJsonSchemaMap[name]();
    // + 设置当前预设组件的初始状态
    preInitialStatus(defaultComJsonSchema, name);
    // + 将当前预设组件的初始状态 加入 preSettingComs
    preSettingComsMap[name] = defaultComJsonSchema;
  });
  return preSettingComsMap as Record<IPreSettingComsUnions, IJsonSchema>;
};

// * 预设组件 的初始状态
export const preInitialStatus = (
  comStatus: IJsonSchema,
  preSettingCompName: IPreSettingComsUnions,
) => {
  switch (preSettingCompName) {
    case "personal-info-name": {
      comStatus.name = "personal-info-name";
      comStatus.status.title.status = "您的姓名是";
      comStatus.status.desc.status = "请输入您的姓名";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-id": {
      comStatus.name = "personal-info-id";
      comStatus.status.title.status = "您的身份证号是";
      comStatus.status.desc.status = "请输入您的身份证号";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-birth": {
      comStatus.name = "personal-info-birth";
      comStatus.status.title.status = "您的出生日期是";
      comStatus.status.desc.status = "请选择您的出生日期";
      comStatus.status.dateType!.isShow = false;
      break;
    }
    case "personal-info-gender": {
      comStatus.name = "personal-info-gender";
      comStatus.status.title.status = "您的性别是";
      comStatus.status.desc.status = "请选择您的性别";
      comStatus.status.options!.status = ["男", "女", "保密"];
      break;
    }
    case "personal-info-age": {
      comStatus.name = "personal-info-age";
      comStatus.status.title.status = "您的年龄是";
      comStatus.status.desc.status = "请输入您的年龄";
      // comStatus.status.inputType!.currentStatusIndex = 2;
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-education": {
      comStatus.name = "personal-info-education";
      comStatus.status.title.status = "您的学历是";
      comStatus.status.desc.status = "请选择您的学历";
      comStatus.status.options!.status = [
        "初中及以下",
        "高中/中专/技校",
        "大学专科",
        "大学本科",
        "硕士及以上",
      ];
      break;
    }
    case "personal-info-collage": {
      comStatus.name = "personal-info-collage";
      comStatus.status.title.status = "您的大学是";
      comStatus.status.desc.status = "请输入您的大学";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-major": {
      comStatus.name = "personal-info-major";
      comStatus.status.title.status = "您的专业是";
      comStatus.status.desc.status = "请输入您的专业";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-industry": {
      comStatus.name = "personal-info-industry";
      comStatus.status.title.status = "您的行业是";
      comStatus.status.desc.status = "请输入您的行业";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-company": {
      comStatus.name = "personal-info-company";
      comStatus.status.title.status = "您的公司是";
      comStatus.status.desc.status = "请输入您的公司";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "personal-info-career": {
      comStatus.name = "personal-info-career";
      comStatus.status.title.status = "您的职业是";
      comStatus.status.desc.status = "请选择您的职业";
      comStatus.status.options!.status = [
        "在校学生",
        "政府/机关干部/公务员",
        "企业管理者（包括基层及中高层管理者）",
        "专业人员（如医生/律师/文体/记者/老师等）",
        "普通职员（办公室/写字楼工作人员）",
        "普通工人（如工厂工人/体力劳动者等）",
        "商业服务业职工（如销售人员/商店职员/服务员等）",
        "个体经营者/承包商",
        "自由职业者",
        "农林牧渔劳动者",
        "退休",
        "暂无职业",
        "其他",
      ];
      break;
    }
    case "personal-info-position": {
      comStatus.name = "personal-info-position";
      comStatus.status.title.status = "您的职位是";
      comStatus.status.desc.status = "请输入您的职位";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "contact-way-phone": {
      comStatus.name = "contact-way-phone";
      comStatus.status.title.status = "您的手机号是";
      comStatus.status.desc.status = "请输入您的手机号";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "contact-way-wechat": {
      comStatus.name = "contact-way-wechat";
      comStatus.status.title.status = "您的微信是";
      comStatus.status.desc.status = "请输入您的微信";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "contact-way-qq": {
      comStatus.name = "contact-way-qq";
      comStatus.status.title.status = "您的QQ是";
      comStatus.status.desc.status = "请输入您的QQ";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "contact-way-email": {
      comStatus.name = "contact-way-email";
      comStatus.status.title.status = "您的邮箱是";
      comStatus.status.desc.status = "请输入您的邮箱";
      comStatus.status.inputType!.isShow = false;
      break;
    }
    case "contact-way-address": {
      comStatus.name = "contact-way-address";
      comStatus.status.title.status = "您的地址是";
      comStatus.status.desc.status = "请输入您的地址";
      comStatus.status.inputType!.isShow = false;
      break;
    }
  }
};
